/***************************************************************************
 *   KShootout - online shootout card game.                                *
 *   Copyright (C) 2008, 2009  MacJariel                                   *
 *                                                                         *
 *   KShootout is free software: you can redistribute it and/or modify     *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation, either version 3 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   KShootout is distributed in the hope that it will be useful,          *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with KShootout.  If not, see <http://www.gnu.org/licenses/>.    *
 ***************************************************************************/
#ifndef __PLAYERWIDGET_H__
#define __PLAYERWIDGET_H__

#include <QWidget>
#include "gametypes.h"

class QLabel;

namespace client
{

    class CardListWidget;
    class CardWidget;
    class CharacterWidget;
    class GameActionMgr;

    /**
     * The PlayerWidget class provides common base class for opponents' widgets
     * and local player widget.
     * @author MacJariel
     */
    class PlayerWidget: public QWidget
    {
        Q_OBJECT;
    public:
        /// Constructs a player widget.
        PlayerWidget(QWidget* parent);

        /// Destroys the player widget.
        virtual ~PlayerWidget();

        /// Player widgets (especially local player widget) need to generate
        /// game events. Pointer to the game-action manager should be provided
        /// as soon as possible.
        void setGameActionMgr(const GameActionMgr* gameActionMgr);

        /// Update player widget according to PlayerData.
        /// You can either reimplement this method to do everything again in
        /// your subclass, or you can use reasonable implementation and
        /// reimplement protected widget accessors.
        virtual void update(const PlayerData& newPlayerData);

        /// Returns whether the widget contains a player.
        bool isVoid() const;

        /// Returns whether the controlled player is local or not
        virtual bool isLocalPlayer() const = 0;

        /// Sets the widget according the PlayerData structure.
        void setFromPlayerData(const PlayerData&);

        /// Clears the widget to the original state.
        void clear();

        /// Sets the contained player to be "current".
        void setCurrent(bool isCurrent);

        /// Sets the contained player to be "requested".
        void setRequested(bool isRequested);

        /// Returns the hand widget.
        virtual CardListWidget* handWidget() = 0;

        /// Returns the table widget.
        virtual CardListWidget* tableWidget() = 0;

    protected:
        /// Returns the character widget.
        virtual CharacterWidget* characterWidget() = 0;

        /// Returns the avatar label widget.
        virtual QLabel* avatarLabel() = 0;

        /// Returns the player name label widget.
        virtual QLabel* playerNameLabel() = 0;

        /// Returns the role card widget or 0 if role card does not exist.
        virtual CardWidget* roleWidget() = 0;

        /// This method draws frames around the player widget, according to the
        /// isCurrent and isRequested properties.
        virtual void paintEvent(QPaintEvent*);

        /// Handles the mouse press event on the widget. The event is delegated
        /// to GameActionMgr, if it was set.
        virtual void mousePressEvent(QMouseEvent*);

    protected:
        GameActionMgr*  mp_gameActionMgr;
        bool            m_isCurrent;
        bool            m_isRequested;
        PlayerId        m_playerId;

    private:
        void setCardListRevealed(CardListWidget*, const CardListData&);
        void setCardListUnrevealed(CardListWidget*, quint8 cardCount);
//        void updateAvatarLabel();
//        void createWinnerIcon();
    };
}
#endif
